using UnityEngine;
using UnityEngine.SceneManagement;

public class LevelManager : MonoBehaviour
{
	public LevelPreset[] LevelPresets;

	public GameObject Preloader;

	private string currentLevel;

	private void OnEnable()
	{
		SceneManager.sceneLoaded += OnLevelFinishedLoading;
	}

	private void OnDisable()
	{
		SceneManager.sceneLoaded -= OnLevelFinishedLoading;
	}

	public LevelPreset GetLevel(int index)
	{
		if (LevelPresets.Length > 0 && LevelPresets.Length > index)
		{
			return LevelPresets[index];
		}
		return null;
	}

	public LevelPreset GetCurrentLevel()
	{
		for (int i = 0; i < LevelPresets.Length; i++)
		{
			if (LevelPresets[i] != null && LevelPresets[i].SceneName == currentLevel)
			{
				return LevelPresets[i];
			}
		}
		return null;
	}

	private void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
	{
		currentLevel = scene.name;
		if (Preloader != null)
		{
			Preloader.SetActive(value: false);
		}
	}

	public void OnGameIsBegin()
	{
		if (Preloader != null)
		{
			Preloader.SetActive(value: true);
		}
	}

	public void OnGameplay()
	{
		if (Preloader != null)
		{
			Preloader.SetActive(value: false);
		}
	}

	private bool isSceneCurrentlyLoaded(string sceneName_no_extention)
	{
		for (int i = 0; i < SceneManager.sceneCount; i++)
		{
			if (SceneManager.GetSceneAt(i).name == sceneName_no_extention)
			{
				return true;
			}
		}
		return false;
	}

	private void Update()
	{
		if (UnitZ.gameManager.IsPlaying && Preloader != null)
		{
			Preloader.SetActive(value: false);
		}
	}
}
